<template>
  <el-dialog
    :title="!dataForm.id ? '新增' : '修改'"
    :close-on-click-modal="false"
    :visible.sync="visible">
    <el-form :model="dataForm" :rules="dataRule" ref="dataForm" @keyup.enter.native="dataFormSubmit()" label-width="80px">
      <el-form-item label="交易主表ID，取值CATEGORY的ID(数字0：未插入)" prop="tradeOrderId">
        <el-input v-model="dataForm.tradeOrderId" placeholder="交易主表ID，取值CATEGORY的ID(数字0：未插入)"></el-input>
      </el-form-item>
      <el-form-item label="留存字段交易关联用户流水ID，取值USER的ID(数字0：未插入)" prop="userId">
        <el-input v-model="dataForm.userId" placeholder="留存字段交易关联用户流水ID，取值USER的ID(数字0：未插入)"></el-input>
      </el-form-item>
      <el-form-item label="用户选择的支付方式的ID,取值表PAY_TOOL表(数字0：未插入)" prop="payToolId">
        <el-input v-model="dataForm.payToolId" placeholder="用户选择的支付方式的ID,取值表PAY_TOOL表(数字0：未插入)"></el-input>
      </el-form-item>
      <el-form-item label="收货人的姓名,用户页面填写,默认取值表USER_ADDRESS(字符串空：未插入)" prop="consignee">
        <el-input v-model="dataForm.consignee" placeholder="收货人的姓名,用户页面填写,默认取值表USER_ADDRESS(字符串空：未插入)"></el-input>
      </el-form-item>
      <el-form-item label="收货人的固定电话,用户页面填写,默认取值表USER_ADDRESS(字符串空：未插入)" prop="tel">
        <el-input v-model="dataForm.tel" placeholder="收货人的固定电话,用户页面填写,默认取值表USER_ADDRESS(字符串空：未插入)"></el-input>
      </el-form-item>
      <el-form-item label="收货人的手机,用户页面填写,默认取值表USER_ADDRESS(字符串空：未插入)" prop="mobile">
        <el-input v-model="dataForm.mobile" placeholder="收货人的手机,用户页面填写,默认取值表USER_ADDRESS(字符串空：未插入)"></el-input>
      </el-form-item>
      <el-form-item label="收货人的最佳送货时间,用户页面填写,默认取值表USER_ADDRESS(字符串空：未插入)" prop="bestTime">
        <el-input v-model="dataForm.bestTime" placeholder="收货人的最佳送货时间,用户页面填写,默认取值表USER_ADDRESS(字符串空：未插入)"></el-input>
      </el-form-item>
      <el-form-item label="收货人的详细地址,用户页面填写,默认取值表USER_ADDRESS(字符串空：未插入)" prop="address">
        <el-input v-model="dataForm.address" placeholder="收货人的详细地址,用户页面填写,默认取值表USER_ADDRESS(字符串空：未插入)"></el-input>
      </el-form-item>
      <el-form-item label="发货物流单号(字符串空：未插入)" prop="shippingOrderId">
        <el-input v-model="dataForm.shippingOrderId" placeholder="发货物流单号(字符串空：未插入)"></el-input>
      </el-form-item>
      <el-form-item label="用户选择的配送方式ID,取值表SHIPPING(字符串空：未插入)" prop="shippingId">
        <el-input v-model="dataForm.shippingId" placeholder="用户选择的配送方式ID,取值表SHIPPING(字符串空：未插入)"></el-input>
      </el-form-item>
      <el-form-item label="订单配送时间(数字0：未插入)" prop="shippingTime">
        <el-input v-model="dataForm.shippingTime" placeholder="订单配送时间(数字0：未插入)"></el-input>
      </el-form-item>
      <el-form-item label="订单应付款金额即商品总额加配送费加包装费等(数字0：未插入)" prop="orderAmount">
        <el-input v-model="dataForm.orderAmount" placeholder="订单应付款金额即商品总额加配送费加包装费等(数字0：未插入)"></el-input>
      </el-form-item>
      <el-form-item label="商品的总金额(数字0：未插入)" prop="goodsAmount">
        <el-input v-model="dataForm.goodsAmount" placeholder="商品的总金额(数字0：未插入)"></el-input>
      </el-form-item>
      <el-form-item label="配送费用即外卖系统比较重要(数字0：未插入)" prop="shippingFee">
        <el-input v-model="dataForm.shippingFee" placeholder="配送费用即外卖系统比较重要(数字0：未插入)"></el-input>
      </el-form-item>
      <el-form-item label="包装费用即点餐打包费外卖系统比较重要(数字0：未插入)" prop="packFee">
        <el-input v-model="dataForm.packFee" placeholder="包装费用即点餐打包费外卖系统比较重要(数字0：未插入)"></el-input>
      </el-form-item>
      <el-form-item label="保价费用(数字0：未插入)" prop="insureFee">
        <el-input v-model="dataForm.insureFee" placeholder="保价费用(数字0：未插入)"></el-input>
      </el-form-item>
      <el-form-item label="留存字段优惠方式标识即优惠类型，即红包ID, USER_BONUS的BONUS_ID(数字0：未插入)" prop="bonusTypeId">
        <el-input v-model="dataForm.bonusTypeId" placeholder="留存字段优惠方式标识即优惠类型，即红包ID, USER_BONUS的BONUS_ID(数字0：未插入)"></el-input>
      </el-form-item>
      <el-form-item label="优惠类型，即红包ID, USER_BONUS的BONUS_ID(数字0：未插入)" prop="bonusId">
        <el-input v-model="dataForm.bonusId" placeholder="优惠类型，即红包ID, USER_BONUS的BONUS_ID(数字0：未插入)"></el-input>
      </el-form-item>
      <el-form-item label="优惠额度，即使用红包抵扣的金额(数字0：未插入)" prop="bonusMoney">
        <el-input v-model="dataForm.bonusMoney" placeholder="优惠额度，即使用红包抵扣的金额(数字0：未插入)"></el-input>
      </el-form-item>
      <el-form-item label="订单状态(数字0：未插入，1已确认; 2已取消; 3无效; 4退货)" prop="orderStatus">
        <el-input v-model="dataForm.orderStatus" placeholder="订单状态(数字0：未插入，1已确认; 2已取消; 3无效; 4退货)"></el-input>
      </el-form-item>
      <el-form-item label="单个商品评分(数字0：未插入)" prop="score">
        <el-input v-model="dataForm.score" placeholder="单个商品评分(数字0：未插入)"></el-input>
      </el-form-item>
      <el-form-item label="商品数量(数字0：未插入，1.是,2：否，)" prop="goodsNumber">
        <el-input v-model="dataForm.goodsNumber" placeholder="商品数量(数字0：未插入，1.是,2：否，)"></el-input>
      </el-form-item>
      <el-form-item label="操作员(字符串空：未插入)" prop="operator">
        <el-input v-model="dataForm.operator" placeholder="操作员(字符串空：未插入)"></el-input>
      </el-form-item>
      <el-form-item label="创建即上传时间(数字0：未插入)" prop="createUtc">
        <el-input v-model="dataForm.createUtc" placeholder="创建即上传时间(数字0：未插入)"></el-input>
      </el-form-item>
      <el-form-item label="修改即更新时间(数字0：未插入)" prop="modifyUtc">
        <el-input v-model="dataForm.modifyUtc" placeholder="修改即更新时间(数字0：未插入)"></el-input>
      </el-form-item>
      <el-form-item label="是否删除(数字0：未插入，1.未删除,2：删除，)" prop="isDeleted">
        <el-input v-model="dataForm.isDeleted" placeholder="是否删除(数字0：未插入，1.未删除,2：删除，)"></el-input>
      </el-form-item>
      <el-form-item label="版本号(数字0：未插入)" prop="version">
        <el-input v-model="dataForm.version" placeholder="版本号(数字0：未插入)"></el-input>
      </el-form-item>
    </el-form>
    <span slot="footer" class="dialog-footer">
      <el-button @click="visible = false">取消</el-button>
      <el-button type="primary" @click="dataFormSubmit()">确定</el-button>
    </span>
  </el-dialog>
</template>

<script>
  import API from '@/api'
  export default {
    data () {
      return {
        visible: false,
        dataForm: {
          id: 0,
          tradeOrderId: '',
          userId: '',
          payToolId: '',
          consignee: '',
          tel: '',
          mobile: '',
          bestTime: '',
          address: '',
          shippingOrderId: '',
          shippingId: '',
          shippingTime: '',
          orderAmount: '',
          goodsAmount: '',
          shippingFee: '',
          packFee: '',
          insureFee: '',
          bonusTypeId: '',
          bonusId: '',
          bonusMoney: '',
          orderStatus: '',
          score: '',
          goodsNumber: '',
          operator: '',
          createUtc: '',
          modifyUtc: '',
          isDeleted: '',
          version: ''
        },
        dataRule: {
          tradeOrderId: [
            { required: true, message: '交易主表ID，取值CATEGORY的ID(数字0：未插入)不能为空', trigger: 'blur' }
          ],
          userId: [
            { required: true, message: '留存字段交易关联用户流水ID，取值USER的ID(数字0：未插入)不能为空', trigger: 'blur' }
          ],
          payToolId: [
            { required: true, message: '用户选择的支付方式的ID,取值表PAY_TOOL表(数字0：未插入)不能为空', trigger: 'blur' }
          ],
          consignee: [
            { required: true, message: '收货人的姓名,用户页面填写,默认取值表USER_ADDRESS(字符串空：未插入)不能为空', trigger: 'blur' }
          ],
          tel: [
            { required: true, message: '收货人的固定电话,用户页面填写,默认取值表USER_ADDRESS(字符串空：未插入)不能为空', trigger: 'blur' }
          ],
          mobile: [
            { required: true, message: '收货人的手机,用户页面填写,默认取值表USER_ADDRESS(字符串空：未插入)不能为空', trigger: 'blur' }
          ],
          bestTime: [
            { required: true, message: '收货人的最佳送货时间,用户页面填写,默认取值表USER_ADDRESS(字符串空：未插入)不能为空', trigger: 'blur' }
          ],
          address: [
            { required: true, message: '收货人的详细地址,用户页面填写,默认取值表USER_ADDRESS(字符串空：未插入)不能为空', trigger: 'blur' }
          ],
          shippingOrderId: [
            { required: true, message: '发货物流单号(字符串空：未插入)不能为空', trigger: 'blur' }
          ],
          shippingId: [
            { required: true, message: '用户选择的配送方式ID,取值表SHIPPING(字符串空：未插入)不能为空', trigger: 'blur' }
          ],
          shippingTime: [
            { required: true, message: '订单配送时间(数字0：未插入)不能为空', trigger: 'blur' }
          ],
          orderAmount: [
            { required: true, message: '订单应付款金额即商品总额加配送费加包装费等(数字0：未插入)不能为空', trigger: 'blur' }
          ],
          goodsAmount: [
            { required: true, message: '商品的总金额(数字0：未插入)不能为空', trigger: 'blur' }
          ],
          shippingFee: [
            { required: true, message: '配送费用即外卖系统比较重要(数字0：未插入)不能为空', trigger: 'blur' }
          ],
          packFee: [
            { required: true, message: '包装费用即点餐打包费外卖系统比较重要(数字0：未插入)不能为空', trigger: 'blur' }
          ],
          insureFee: [
            { required: true, message: '保价费用(数字0：未插入)不能为空', trigger: 'blur' }
          ],
          bonusTypeId: [
            { required: true, message: '留存字段优惠方式标识即优惠类型，即红包ID, USER_BONUS的BONUS_ID(数字0：未插入)不能为空', trigger: 'blur' }
          ],
          bonusId: [
            { required: true, message: '优惠类型，即红包ID, USER_BONUS的BONUS_ID(数字0：未插入)不能为空', trigger: 'blur' }
          ],
          bonusMoney: [
            { required: true, message: '优惠额度，即使用红包抵扣的金额(数字0：未插入)不能为空', trigger: 'blur' }
          ],
          orderStatus: [
            { required: true, message: '订单状态(数字0：未插入，1已确认; 2已取消; 3无效; 4退货)不能为空', trigger: 'blur' }
          ],
          score: [
            { required: true, message: '单个商品评分(数字0：未插入)不能为空', trigger: 'blur' }
          ],
          goodsNumber: [
            { required: true, message: '商品数量(数字0：未插入，1.是,2：否，)不能为空', trigger: 'blur' }
          ],
          operator: [
            { required: true, message: '操作员(字符串空：未插入)不能为空', trigger: 'blur' }
          ],
          createUtc: [
            { required: true, message: '创建即上传时间(数字0：未插入)不能为空', trigger: 'blur' }
          ],
          modifyUtc: [
            { required: true, message: '修改即更新时间(数字0：未插入)不能为空', trigger: 'blur' }
          ],
          isDeleted: [
            { required: true, message: '是否删除(数字0：未插入，1.未删除,2：删除，)不能为空', trigger: 'blur' }
          ],
          version: [
            { required: true, message: '版本号(数字0：未插入)不能为空', trigger: 'blur' }
          ]
        }
      }
    },
    methods: {
      init (id) {
        this.dataForm.id = id || 0
        this.visible = true
        this.$nextTick(() => {
          this.$refs['dataForm'].resetFields()
          if (this.dataForm.id) {
            API.upktradesubgoodorder.info(this.dataForm.id).then(({data}) => {
              if (data && data.code === 0) {
                this.dataForm.tradeOrderId = data.upktradesubgoodorder.tradeOrderId
                this.dataForm.userId = data.upktradesubgoodorder.userId
                this.dataForm.payToolId = data.upktradesubgoodorder.payToolId
                this.dataForm.consignee = data.upktradesubgoodorder.consignee
                this.dataForm.tel = data.upktradesubgoodorder.tel
                this.dataForm.mobile = data.upktradesubgoodorder.mobile
                this.dataForm.bestTime = data.upktradesubgoodorder.bestTime
                this.dataForm.address = data.upktradesubgoodorder.address
                this.dataForm.shippingOrderId = data.upktradesubgoodorder.shippingOrderId
                this.dataForm.shippingId = data.upktradesubgoodorder.shippingId
                this.dataForm.shippingTime = data.upktradesubgoodorder.shippingTime
                this.dataForm.orderAmount = data.upktradesubgoodorder.orderAmount
                this.dataForm.goodsAmount = data.upktradesubgoodorder.goodsAmount
                this.dataForm.shippingFee = data.upktradesubgoodorder.shippingFee
                this.dataForm.packFee = data.upktradesubgoodorder.packFee
                this.dataForm.insureFee = data.upktradesubgoodorder.insureFee
                this.dataForm.bonusTypeId = data.upktradesubgoodorder.bonusTypeId
                this.dataForm.bonusId = data.upktradesubgoodorder.bonusId
                this.dataForm.bonusMoney = data.upktradesubgoodorder.bonusMoney
                this.dataForm.orderStatus = data.upktradesubgoodorder.orderStatus
                this.dataForm.score = data.upktradesubgoodorder.score
                this.dataForm.goodsNumber = data.upktradesubgoodorder.goodsNumber
                this.dataForm.operator = data.upktradesubgoodorder.operator
                this.dataForm.createUtc = data.upktradesubgoodorder.createUtc
                this.dataForm.modifyUtc = data.upktradesubgoodorder.modifyUtc
                this.dataForm.isDeleted = data.upktradesubgoodorder.isDeleted
                this.dataForm.version = data.upktradesubgoodorder.version
              }
            })
          }
        })
      },
      // 表单提交
      dataFormSubmit () {
        this.$refs['dataForm'].validate((valid) => {
          if (valid) {
            var params = {
              'id': this.dataForm.id || undefined,
              'tradeOrderId': this.dataForm.tradeOrderId,
              'userId': this.dataForm.userId,
              'payToolId': this.dataForm.payToolId,
              'consignee': this.dataForm.consignee,
              'tel': this.dataForm.tel,
              'mobile': this.dataForm.mobile,
              'bestTime': this.dataForm.bestTime,
              'address': this.dataForm.address,
              'shippingOrderId': this.dataForm.shippingOrderId,
              'shippingId': this.dataForm.shippingId,
              'shippingTime': this.dataForm.shippingTime,
              'orderAmount': this.dataForm.orderAmount,
              'goodsAmount': this.dataForm.goodsAmount,
              'shippingFee': this.dataForm.shippingFee,
              'packFee': this.dataForm.packFee,
              'insureFee': this.dataForm.insureFee,
              'bonusTypeId': this.dataForm.bonusTypeId,
              'bonusId': this.dataForm.bonusId,
              'bonusMoney': this.dataForm.bonusMoney,
              'orderStatus': this.dataForm.orderStatus,
              'score': this.dataForm.score,
              'goodsNumber': this.dataForm.goodsNumber,
              'operator': this.dataForm.operator,
              'createUtc': this.dataForm.createUtc,
              'modifyUtc': this.dataForm.modifyUtc,
              'isDeleted': this.dataForm.isDeleted,
              'version': this.dataForm.version
            }
            var tick = !this.dataForm.id ? API.upktradesubgoodorder.add(params) : API.upktradesubgoodorder.update(params)
            tick.then(({data}) => {
              if (data && data.code === 0) {
                this.$message({
                  message: '操作成功',
                  type: 'success',
                  duration: 1500,
                  onClose: () => {
                    this.visible = false
                    this.$emit('refreshDataList')
                  }
                })
              } else {
                this.$message.error(data.msg)
              }
            })
          }
        })
      }
    }
  }
</script>
